<template>
<div> <!--     action是必须要的  -->
  <el-upload
      style="display: inline-block; margin:0 10px"
      :http-request="handleUpload"
      :show-file-list="true"
      :on-success="importSuccess"
  >
    <el-button type="info">导入</el-button>
  </el-upload>
</div>
</template>

<script setup>
import {ElMessage} from "element-plus";
import {uploadFile} from "@/api/file.js";


const handleUpload=async (options) => {
  try {
    // options.file 是选中的文件对象

    // 调用API函数，传入formData
    // 上传成功后调用on-success回调
    // options.onSuccess(res);
    return await uploadFile(options.file);
  } catch (error) {
    // 处理上传失败
    options.onError(error);
    ElMessage.error('上传失败：' + (error.message || '网络错误'));
  }
};

const importSuccess=(res)=>{

  if(res.code==='200'){
    ElMessage.success('批量导入成功')

  }else{
    ElMessage.error('导入失败')
  }
}


</script>


<style scoped>

</style>